<div class="box-page-container">
  <div class="box-page-header">
    <div class="title">Пользователи</div>
    <div class="other-controls right">
    </div>
  </div>
  <div class="box-page-body">
    <div class="box-message" id="message" style="display: none"></div>
    <table class="table">
      <thead>
        <tr>
          <th width="25px">ID</th>
          <th width="120px">Логин</th>
          <th width="120px">Имя</th>
          <th width="120px">e-mail</th>
          <th width="200px">Группы</th>
          <th width="30px"></th>
        </tr>
      </thead>
      <tbody>
      <?php foreach ($this->users as $user): ?>
          <tr id="<?php echo $user->id ?>">
            <td><?php echo $user->id ?></td>
            <td><?php echo $user->login ?></td>
            <td><?php echo $user->name ?></td>
            <td><?php echo $user->email ?></td>
            <td><?php
                $groups = array();
                $groupRowset = $user->findDependentRowset('Model_UserGroup', 'User');
                // получаем группы пользователя
                foreach($groupRowset as $group) {
                    $groups[] = ucfirst($group->findParentRow('Model_Groups')->title);
                }
                echo trim(implode(', ', $groups), ',');
            ?></td>
            <td>
              <div class="control-bar">
                <a href="/cp/user/edit?id=<?php echo $user->id ?>" title="Редактировать"><i class="icon-pencil"></i></a>
                <?php if ($user->id != 1 && $user->id != 2): ?>
					<a href="#" title="Удалить" onclick="dDelete(this); return false;"><i class="icon-trash"></i></a>
				<?php endif; ?>
              </div>
            </td>
          </tr>
      <?php endforeach; ?>
      </tbody>
    </table> 
  </div>
  <div class="box-page-footer">
    <div class="box-controls">
      <div class="right">
       	<div class="btn"><button onclick="window.location = '/cp/user/create'; return false;" class="primary">Добавить пользователя</button></div>
      </div>
      <div id="progress" class="progress ajax-preloader-base"></div>
      <div id="control_text" class="box-controls-text"></div>
      <div class="clear-fix"></div>
    </div>
  </div>
  <div class="clear-fix"></div>
</div>
<script>
function dDelete(el) {
	var title = $(el).parent().parent().parent().find('td').eq(2).text();
	var id = $(el).parent().parent().parent().attr('id');
	var ddel = new goog.ui.Dialog(null, true);
	// new page content
	var ddelc = '<div>Вы действительно хотите удалить пользователя <b>' + title + '</b>?</div>';
	ddel.setContent(ddelc);
	ddel.setTitle('Подтвердите удаление');
	ddel.setButtonSet(
		new goog.ui.Dialog.ButtonSet()
		.addButton({key: 'ok', caption: 'Да'}, true)
		.addButton({key: 'cancel', caption: 'Нет'}, false, true)
	);
	ddel.setVisible(true);
	$(ddel.getElement()).css({'width': '450px', 'left': (document.width / 2) - 225 + 'px'});
	goog.events.listen(ddel, goog.ui.Dialog.EventType.SELECT, function(e){
		if (e.key == 'ok') {
			window.location = '/cp/user/delete?id=' + id;
		}
	});
}
</script>